ninejs.extend(function( exports ) {
	var slider = {
		initialize: function( options ) {
			this.slideElem = document.getElementById(options.slideId || 'imgs');
			this.thumbElem = document.getElementById(options.thumbId || "num");
			this.slides = this.slideElem.getElementsByTagName('li');
			this.thumbs = this.thumbElem.getElementsByTagName("li");
			this.delay = options.delay || 3000;
			this.autoPlay = options.autoPlay || false;
			
			this.prevIndex = 0;
			this.currIndex = 0;
			this.intervalId = null;

			this.slideElem.style.width = this.slides.length * this.slides[0].offsetWidth + "px";

			this.autoPlay && this.start();
		},
		change: function() {
			var _this, item;

			for ( var i = 0; i < this.thumbs.length; i++ ) {
				item = this.thumbs[i];

				item.index = i;
				item.onclick = function() {
					clearInterval(_this.intervalId);

					_this.currIndex = this.index;
					_this.changeThumbClass();

					_this.slideElem.style.left = -(_this.slides[0].offsetWidth * _this.currIndex) + "px";         
				};
				item.onmouseout = function() {
					_this.autoPlay && _this.start();
				};
			}
		},
		changeThumbClass: function() {
			for ( var i = 0; i < this.thumbs.length; i++ ) {
				if ( this.currIndex == this.thumbs[k].index ) {
					this.thumbs[k].className = 'a';
				} else {
					this.thumbs[k].className = 'b';
				}
			}
		},
		changeIndex: function() {
			if ( this.currIndex >= this.thumbs.length - 1 ) {
				this.currIndex = 0;
			} else {
				this.currIndex++;
			}
		},
		start: function() {
			var _this = this;

			this.intervalId && clearInterval(this.intervalId);
			this.intervalId = setInterval(function() {
				_this.changeIndex();
				_this.changeThumbClass();

				_this.slideElem.style.left = -(_this.slides[0].offsetWidth * _this.currIndex) + "px";
			}, this.delay);

			this.change();
		}
	};

	exports.slider = slider;
});